feat(workspace): add file-tree add-to-chat action#233
feat(workspace): add file-tree add-to-chat action#233DerrickBarra wants to merge 7 commits intodaggerhashimoto:masterfrom
Conversation
📝 WalkthroughWalkthroughThis PR implements a feature enabling users to add workspace file paths to chat from the file tree panel. The changes introduce an Changes
Sequence DiagramsequenceDiagram
actor User
participant FileTree as FileTreePanel
participant App
participant ChatPanel
participant InputBar as InputBar
User->>FileTree: Right-click file in tree
FileTree->>FileTree: Open context menu
User->>FileTree: Click "Add to chat"
FileTree->>App: onAddToChat(path, 'file')
App->>ChatPanel: chatPanelRef.current?.addWorkspacePath(path, 'file')
ChatPanel->>InputBar: inputBarRef.current?.addWorkspacePath(path, 'file')
InputBar->>InputBar: Process and add path
InputBar-->>ChatPanel: Promise resolved
ChatPanel-->>App: Promise resolved
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
9a6ba09 to
0215573
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/features/file-browser/FileTreePanel.tsx (1)
672-672: Use the existing trash helper for path classification consistency.
startsWith('.trash')can also match non-trash dotfiles (for example,.trash-notes.md). Consider usingisTrashItemPath(menuPath)plus explicit.trashroot checks.Possible cleanup
- const showAddToChat = Boolean(onAddToChat && menuEntry?.type === 'file' && !menuPath.startsWith('.trash') && menuPath !== '.trash'); + const menuIsTrashRoot = menuPath === '.trash'; + const menuIsTrashItem = isTrashItemPath(menuPath); + const showAddToChat = Boolean(onAddToChat && menuEntry?.type === 'file' && !menuIsTrashRoot && !menuIsTrashItem);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/features/file-browser/FileTreePanel.tsx` at line 672, Replace the ad-hoc startsWith check with the project helper: update the showAddToChat condition (where onAddToChat, menuEntry, menuPath are used) to use isTrashItemPath(menuPath) for trash classification and still explicitly disallow the root '.trash' path; i.e., remove startsWith('.trash') and use !isTrashItemPath(menuPath) && menuPath !== '.trash' alongside the existing onAddToChat and menuEntry?.type === 'file' checks so trash detection is consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/features/file-browser/FileTreePanel.tsx`:
- Around line 800-803: The onClick handler currently drops the promise returned
by onAddToChat (called in FileTreePanel's onClick) which can lead to unhandled
rejections; wrap the call to onAddToChat in an async flow and handle failures
(either await in an async function or attach .catch) to surface errors and avoid
unhandled rejections — e.g., call an async wrapper that calls await
onAddToChat(menuEntry.path, 'file') inside try/catch and handle/report the error
(e.g., show a toast or log and restore UI state) after clearing
setContextMenu(null).
---
Nitpick comments:
In `@src/features/file-browser/FileTreePanel.tsx`:
- Line 672: Replace the ad-hoc startsWith check with the project helper: update
the showAddToChat condition (where onAddToChat, menuEntry, menuPath are used) to
use isTrashItemPath(menuPath) for trash classification and still explicitly
disallow the root '.trash' path; i.e., remove startsWith('.trash') and use
!isTrashItemPath(menuPath) && menuPath !== '.trash' alongside the existing
onAddToChat and menuEntry?.type === 'file' checks so trash detection is
consistent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b2d8fe68-7a46-48cd-a73d-7fe6b1565a21
📒 Files selected for processing (4)
src/App.tsxsrc/features/chat/ChatPanel.tsxsrc/features/file-browser/FileTreePanel.test.tsxsrc/features/file-browser/FileTreePanel.tsx
| onClick={() => { | ||
| setContextMenu(null); | ||
| void onAddToChat?.(menuEntry.path, 'file'); | ||
| }} |
There was a problem hiding this comment.
Handle async failures from onAddToChat instead of dropping them.
Line 802 intentionally discards the returned promise. If staging fails, this can become an unhandled rejection and a silent UX failure.
Proposed fix
- onClick={() => {
- setContextMenu(null);
- void onAddToChat?.(menuEntry.path, 'file');
- }}
+ onClick={async () => {
+ setContextMenu(null);
+ try {
+ await onAddToChat?.(menuEntry.path, 'file');
+ } catch (err) {
+ const message = err instanceof Error ? err.message : 'Failed to add file to chat';
+ showToastForAgent(workspaceAgentId, { type: 'error', message }, 4500);
+ }
+ }}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/features/file-browser/FileTreePanel.tsx` around lines 800 - 803, The
onClick handler currently drops the promise returned by onAddToChat (called in
FileTreePanel's onClick) which can lead to unhandled rejections; wrap the call
to onAddToChat in an async flow and handle failures (either await in an async
function or attach .catch) to surface errors and avoid unhandled rejections —
e.g., call an async wrapper that calls await onAddToChat(menuEntry.path, 'file')
inside try/catch and handle/report the error (e.g., show a toast or log and
restore UI state) after clearing setContextMenu(null).
Summary
Implements the next small stacked attachment slice after the canonical contract and composer simplification work by adding a workspace file-tree
Add to chataction for existing workspace files.In Plain English
This PR lets users add an existing workspace file to chat directly from the file tree.
That matters because if a file is already in the workspace, people should not have to re-upload it or jump through extra steps just to reference it in a conversation. The UI should let them point at the file they already have and bring it into chat cleanly.
This change adds that direct file-tree action while keeping the result inside the existing canonical workspace-reference flow. In short: faster file-to-chat handoff, with less friction and less duplication.
Stacking / dependency
This PR is intentionally stacked on top of:
If those earlier slices change materially, this PR will be revised accordingly.
What changed
Add to chataction for existing workspace filesDeliberately not included
To keep this slice small and reviewable, it does not include:
Verification
src/features/file-browser/FileTreePanel.test.tsxsrc/features/chat/InputBar.test.tsxtsc -p tsconfig.json --noEmitRelated to #232
Depends on #229
Depends on #231
Summary by CodeRabbit
New Features
Tests